package com.gruopbuying.agent.controller;

import com.gruopbuying.agent.pojo.StoreAccountEnumConstants;
import com.gruopbuying.agent.pojo.StoreAgentAccountDO;
import com.gruopbuying.agent.service.StoreAgentAccountService;
import com.gruopbuying.agent.utils.PageUtils;
import com.gruopbuying.agent.utils.Query;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/10/22.
 */
@RestController
@RequestMapping("/agent/store/storeAccount")
public class StoreAgentAccountController {

    @Autowired
    private StoreAgentAccountService storeAccountService;
    public static final Logger logger = LoggerFactory.getLogger(StoreAgentAccountController.class);

    @GetMapping()
    @RequiresPermissions("agent:storeAccount:storeAccount")
    String StoreAccount(){
        return "agent/storeAccount/storeAccount";
    }


    @GetMapping("/list")
    @RequiresPermissions("agent:storeAccount:storeAccount")
    public PageUtils list(@RequestParam Map<String, Object> params){
        logger.info("StoreAgentAccountController.params()----->通过代理商id添加服务商获取的列表参数:"+params.toString());
        //查询列表数据
        Query query = new Query(params);
        List<StoreAgentAccountDO> storeAccountList = storeAccountService.list(query);
        for(StoreAgentAccountDO StoreAgentAccountDO :storeAccountList){
            String status = StoreAgentAccountDO.getStatus();
            if(StoreAccountEnumConstants.ENUM_STATUS_NORMAL.equals(status)){
                StoreAgentAccountDO.setStatus("审核通过");
            }else if(StoreAccountEnumConstants.ENUM_STATUS_WAIT.equals(status)){
                StoreAgentAccountDO.setStatus("待审核");
            }else if(StoreAccountEnumConstants.ENUM_STATUS_REJECT.equals(status)){
                StoreAgentAccountDO.setStatus("审核驳回");
            }
        }
        int total = storeAccountService.count(query);
        PageUtils pageUtils = new PageUtils(storeAccountList, total);
        return pageUtils;
    }



    @GetMapping("/edit/{accountId}")
    @RequiresPermissions("agent:storeAccount:edit")
    String edit(@PathVariable("accountId") String accountId, Model model){
        StoreAgentAccountDO storeAccount = storeAccountService.get(accountId);
        model.addAttribute("storeAccount", storeAccount);
        return "admin/storeAccount/edit";
    }



    /**
     *通过代理商id查服务商门店信息
     */
    @GetMapping("/storeMainInfoListByAgent")
    public PageUtils storeMainInfoListByAgent(@RequestParam Map<String, Object> params){
        logger.info("StoreAgentAccountController.storeMainInfoListByAgent()----->通过代理商id获取门店列表参数:"+params.toString());
        PageUtils storeMainInfoListByAgentList = storeAccountService.storeMainInfoListByAgent(params);
        return storeMainInfoListByAgentList;
    }

    /**
     *通过代理商门店运营人员信息
     */
    @GetMapping("/getStoreOperList")
    public PageUtils getStoreOperList(@RequestParam Map<String, Object> params){
        logger.info("StoreAgentAccountController.getStoreOperList()----->通过代理商id获取门店运营人员列表参数:"+params.toString());
        PageUtils getStoreOperList = storeAccountService.getStoreOperList(params);
        return getStoreOperList;
    }




}
